#include <iostream>
#include "netWork.h"
#include "../common/common.h"
using namespace std;

Network network;

#ifdef DEBUG
#endif

int main(int argc, char *argv[])
{
    clientInfo client;

    memset(&client,0,sizeof(clientInfo));
    //init
    int status = network.creat_socket_fd();
    if (status == -1)
    {
        cout << "creat_socket_fd error!" << endl;
        goto error;
    }

    status = network.bind_socket_point();
    if (status == -1)
    {
        cout << "bind_socket_point error!" << endl;
        goto error;
    }

    while (1)
    {
        network.recv_socket_data();
        switch (network.buf_recv[5]) //获取客户端外网ip和port
        {
        case '1':
            memcpy(client.ip,inet_ntoa(network.cliaddr.sin_addr),strlen(inet_ntoa(network.cliaddr.sin_addr)));
            client.port = ntohs(network.cliaddr.sin_port);
            cout << "port:" << client.port;
            memcpy(network.buf_send,&client,sizeof(client));
            network.send_socket_data(sizeof(client));
            break;

        default:
            break;
        }
    }

error:
    return 0;
}